﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace pswb
{
    public partial class frmUserEditor : Form
    {
        public frmUserEditor()
        {
            InitializeComponent();
        }

        private void frmUserEditor_Load(object sender, EventArgs e)
        {
            //create a child domain
            //AppDomain childDomain = AppDomain.CreateDomain("ChildDomain", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
            
            Assembly myAssembly = Assembly.LoadFrom("TestDynamicLib.dll");

            Type[] types = myAssembly.GetTypes();
            Type type = myAssembly.GetType(types[0].FullName);
            //MethodInfo[] methods = myAssembly.GetType(types[0].Name).GetMethods();
            MethodInfo[] methods = type.GetMethods();
            MethodInfo method = type.GetMethod("TestMethod");
            object[] args = new object[] { (string)"Nilotpal" };

            object methodInstance = myAssembly.CreateInstance(type.FullName);
            object ret = methods[0].Invoke(methodInstance, args);
            Console.WriteLine(ret.ToString());
            ret = method.Invoke(methodInstance, args);
        }
    }
}
